package com.zhxi.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.zhxi.gulimall.product.vo.SpuSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zhxi.gulimall.product.entity.SpuInfoEntity;
import com.zhxi.gulimall.product.service.SpuInfoService;
import com.zhxi.common.utils.PageUtils;
import com.zhxi.common.utils.R;


/**
 * spu信息
 *
 * @Author: zhxi
 * @Email: 664480310@qq.com
 * @Date: 2024-08-19 17:41:15
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;


    /**
     * @param spuId spuId
     * @return {@link R }  上架结果
     * @description: 上架商品
     * @author: zx
     * @date: 2024-10-15 15:16
     */
    @GetMapping("/{spuId}/up")
    public R list(@PathVariable("spuId") long spuId) {
        spuInfoService.up(spuId);
        return R.ok();
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SpuInfoEntity spuInfo = spuInfoService.getById(id);
        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo) {
        spuInfoService.updateById(spuInfo);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        spuInfoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:spuinfo:save")
    public R save(@RequestBody SpuSaveVo vo) {
        //spuInfoService.save(spuInfo);

        spuInfoService.saveSpuInfo(vo);

        return R.ok();
    }
}
